using System;
using System.Collections;
using System.Collections.Generic;
using Timers;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Serialization;

public abstract class Attack : MonoBehaviour
{
    [SerializeField] private string targetTag;
    [SerializeField] private UnityEvent attack;
    protected bool _canAttack = true;
    
    
    private void OnTriggerEnter2D(Collider2D other)
    {
        DoAttack(other);
    }

    protected void CanAttack()
    {
        _canAttack = true;
    }

    private void OnTriggerStay2D(Collider2D other)
    {
        DoAttack(other);
    }

    private void DoAttack(Collider2D other)
    {
        if (!_canAttack) return;            

        if (other.CompareTag(targetTag))
        {
            SubAttackAction(other);
            attack.Invoke();
        }
    }

    protected abstract void SubAttackAction(Collider2D other);
}
